package com.ssy.lingxi.order.controller.web;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.model.vo.basic.request.PreOrderCacheKeyVO;
import com.ssy.lingxi.order.model.vo.basic.request.PreOrderCacheVO;
import com.ssy.lingxi.order.service.web.IPreOrderService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 预下单相关接口
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-20
 */
@RestController
@RequestMapping("/order")
public class PreOrderController {
    @Resource
    private IPreOrderService preOrderService;

    /**
     * 缓存预下单
     * @param headers Http头部信息
     * @param cacheVO 接口参数
     * @return 缓存结果
     */
    @RequestMapping(value = "/cache/set", method = RequestMethod.POST)
    public Wrapper<Void> cachePreOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid PreOrderCacheVO cacheVO) {
        return preOrderService.cachePreOrder(headers, cacheVO);
    }

    /**
     * 查询预下单信息
     * @param headers Http头部信息
     * @param keyVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/cache/get", method = RequestMethod.GET)
    public Wrapper<String> getCachedPreOrder(@RequestHeader HttpHeaders headers, @Valid PreOrderCacheKeyVO keyVO) {
        return preOrderService.getCachedPreOrder(headers, keyVO);
    }

    /**
     * 删除预下单信息
     * @param headers Http头部信息
     * @param keyVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/cache/delete", method = RequestMethod.POST)
    public Wrapper<Void> deleteCachedPreOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid PreOrderCacheKeyVO keyVO) {
        return preOrderService.deleteCachedPreOrder(headers, keyVO);
    }
}
